package com.yuxi.controller;

import com.yuxi.model.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yuxi on 16/10/23.
 */
@Controller
@RequestMapping("/person")
public class PersonController {

    @RequestMapping("/index")
    @ResponseBody
    public  String index(Model model) {
        List<Person> personList = new ArrayList<Person>();
        Person person = new Person();
        person.setAge(22);
        person.setName("yuxi");

        Person person1 = new Person();
        person1.setAge(44);
        person1.setName("bbbb");


        Person person2= new Person();
        person2.setAge(33);
        person2.setName("ccc");

        personList.add(person);
        personList.add(person1);
        personList.add(person2);

        Person singlePerson = new Person();
        singlePerson.setAge(22);
        singlePerson.setName("yuxi");

        model.addAttribute("singlePerson",singlePerson);
        model.addAttribute("personList",personList);
        return  personList.toString();
    }
}
